var ManageValidator = {};
ManageValidator = {
    form:"form-data",
    reset:"reset"
};

ManageValidator.resetValidator = function(validator){
    $("#"+ManageValidator.reset).on("click",function(){
        if(validator!==undefined) {
            validator.resetForm();
        };
    });
};
ManageValidator.loginValidator = function(){
    var formContainer,validator;
    if(arguments.length==0){
        formContainer = $("#"+ManageValidator.form);
    }
    validator = formContainer.validate({
        rules:{
            username:"required",
            password:"required"
        },
        messages:{
            username:"请输入用户名",
            password:"请输入密码"
        }
    });
    ManageValidator.resetValidator(validator);
};

ManageValidator.articleValidator = function(){
    var formContainer,validator;
    if(arguments.length==0){
        formContainer = $("#"+ManageValidator.form);
    }
    validator = formContainer.validate({
        rules:{
            title:"required",
            channelId:{min:1}
        },
        messages:{
            title:"请填写文章标题",
            channelId:{min:"请选择文章栏目"}
        }
    });
    ManageValidator.resetValidator(validator);
};

ManageValidator.channelValidator = function(){
    var formContainer,validator;
    if(arguments.length==0){
        formContainer = $("#"+ManageValidator.form);
    }
    validator = formContainer.validate({
        rules:{
            title:"required"
        },
        messages:{
            title:"请填写文章标题"
        }
    });
    ManageValidator.resetValidator(validator);
};

ManageValidator.databaseValidator = function(){
    var formContainer,validator;
    if(arguments.length==0){
        formContainer = $("#"+ManageValidator.form);
    }
    validator = formContainer.validate({
        rules:{
            name:"required",
            linkurl:"required"
        },
        messages:{
            name:"请填写数据库名称",
            linkurl:"请填写数据库链接"
        }
    });
    ManageValidator.resetValidator(validator);
};

ManageValidator.faqValidator = function(){
    var formContainer,validator;
    if(arguments.length==0){
        formContainer = $("#"+ManageValidator.form);
    }
    validator = formContainer.validate({
        rules:{
            question:"required",
            answer:"required"
        },
        messages:{
            question:"请填写问题名称",
            answer:"请填写回答信息"
        }
    });
    ManageValidator.resetValidator(validator);
};

ManageValidator.newsValidator = function(){
    var formContainer,validator;
    if(arguments.length==0){
        formContainer = $("#"+ManageValidator.form);
    }
    validator = formContainer.validate({
        rules:{
            title:"required",
            typeid:{required:true,min:1}
        },
        messages:{
            title:"请填写新闻标题",
            typeid:{required:"请选择新闻类型",min:"请选择新闻类型"}
        }
    });
    ManageValidator.resetValidator(validator);
};

ManageValidator.sectionValidator = function () {
    var formContainer,validator;
    if(arguments.length==0){
        formContainer = $("#"+ManageValidator.form);
    }
    validator = formContainer.validate({
        rules:{
            name:"required"
        },
        messages:{
            name:"请填写版块名称"
        }
    });
    ManageValidator.resetValidator(validator);
};